//
// Created by 谢哲 on 2021/5/20.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
constexpr long long mod = 1e8 - 3;

long long ans = 0;
void mergeSort(int l, int r, vector<int>& arr) {
    if (r - l <= 1) return;
    int mid = (l + r) >> 1;
    mergeSort(l, mid, arr);
    mergeSort(mid, r, arr);

    vector<int> tmp(r - l);
    for (int i=l, j=mid; i<mid||j<r; ) {
        if (i<mid&&j<r) {
            if (arr[i] < arr[j]) {
                tmp[i+j-l-mid] = arr[i];
                ++i;
            }
            else {
                tmp[i+j-l-mid] = arr[j];
                ans = (ans + (long long)(mid - i)) % mod;
                ++j;
            }
        }
        else if (i<mid) {
            tmp[i+j-l-mid] = arr[i];
            ++i;
        }
        else {
            tmp[i+j-l-mid] = arr[j];
            ++j;
        }
    }
    for (int i=l; i<r; ++i) {
        arr[i] = tmp[i-l];
    }
}

int main() {
    int n;
    cin >> n;

    vector<int> a(n), b(n);
    vector<int> ai(n), bi(n);
    vector<int> x(n);
    for (int i=0; i<n; ++i) cin >> a[i], ai[i] = i;
    for (int i=0; i<n; ++i) cin >> b[i], bi[i] = i;

    sort(ai.begin(), ai.end(), [&](int i, int j){return a[i] < a[j];});
    sort(bi.begin(), bi.end(), [&](int i, int j){return b[i] < b[j];});

    for (int i=0;i<n;++i) x[bi[i]] = ai[i];
    mergeSort(0, n, x);
    cout << ans;

    return 0;
}
